/**
 * Created by ACER on 2017/4/11.
 */
app.controller('others-profile', function ($scope,$http) {
    var otheruserid=sessionStorage.getItem('otheruserid');
    if(!otheruserid){
        $.alert('用户不存在');
       location.href='#home';
        return;
    }
    $scope.userId = JSON.parse(otheruserid);
     $scope.userInfo = {};

    $scope.getOthersProfile=function(){
        if(otheruserid){
            $http(
                {   method:'get',
                    url:app.netPath+'/users/showOther',
                    params: {userId:$scope.userId}
                }
            ).then(function(res){


                if(!res.data.error){

                    $scope.userInfo=res.data.data;
                    //年龄
                    if($scope.userInfo.userBirthday){

                        $scope.userInfo.age= parseInt((new Date().getTime() - new Date($scope.userInfo.userBirthday).valueOf())/31536000000);

                    }
                    $scope.userInfo.userSexWord = $scope.userInfo.userSex == 0? '男':'女';
                    var avatarImg = {};

                    if(res.data.data.userAvatarAddress){
                        avatarImg.imgAddress = app.netPath+'/resources/img/'+res.data.data.userAvatarAddress;
                        $scope.userInfo.avatarImg = avatarImg;
                    }

                    if($scope.userInfo.userTelphone){
                        $scope.usertelphone =$scope.userInfo.userTelphone.substr(1,4);
                    }
                    if($scope.userInfo.userEmail)
                    { $scope.useremail =$scope.userInfo.userEmail.substr(1,4);}

                }
                else {
                    $.alert('error'+res.data.error+','+res.data.msg)
                }

            },function(){
                $.alert('网络或设置错误');
            })
        }
    };

    $scope.getUserOtherId=function(otheruserid){
        sessionStorage.setItem('otheruserid',otheruserid);
        location.href='#others-profile';
    };

//得到别人id，并存入session
   $scope.getOtherHistory=function(otheruserid){
       location.href='#others-history-release'
   }


});